using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

namespace RichFrame
{
    /// <summary>
    /// 资源管理器
    /// </summary>
    public class AssetsManager : Singleton<AssetsManager>
    {
        /// <summary>
        /// 资源提供器，如果未设置，默认为resources
        /// </summary>
        public IAssetProvider assetProvider
        {  
            get
            {
                if(_assetProvider == null)
                {
                    _assetProvider = new DefaultAssetProvider();
                }
                return _assetProvider;
            }
            set
            {
                _assetProvider = value;
            }
        }
        IAssetProvider _assetProvider;
        /// <summary>
        /// 加载资源
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="assetPath">资源路径</param>
        /// <returns></returns>
        public T LoadAsset<T>(string assetPath) where T : Object
        {
            return assetProvider.LoadAsset<T>(assetPath);
        }
        /// <summary>
        /// 异步加载资源
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="assetPath">资源路径</param>
        /// <returns></returns>
        public AssetRequest LoadAssetAsync<T>(string assetPath) where T : Object
        {
            return assetProvider.LoadAssetAsync<T>(assetPath);
        }

        /// <summary>
        /// 资源提供器
        /// </summary>
        public interface IAssetProvider
        {
            /// <summary>
            /// 加载资源
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <param name="assetPath">资源路径</param>
            /// <returns></returns>
            T LoadAsset<T>(string assetPath) where T : Object;
            /// <summary>
            /// 异步加载资源
            /// </summary>
            /// <typeparam name="T"></typeparam>
            /// <param name="assetPath">资源路径</param>
            /// <returns></returns>
            AssetRequest LoadAssetAsync<T>(string assetPath) where T : Object;
        }
    }
}

